<?php
include_once 'snc-core/config-helper/ConfigHelper.php';
include_once 'snc-core/env/Config.php';
class SystemConfig{
	public static $context;
	protected $inContext;
	function __construct(){
		$this->inContext = self::$context;
	}
	/**
	 * get config of a concret configfile
	 * @return mixed array(configfiles::array(attribute))	 
	 */
	public function getConfig($fileName){
		$isFileExist = Config::isFileExist($fileName);
		$fileLength = strlen($fileName);		
		$extension = 4;
		$cutTo = $fileLength - $extension;
		$name = substr($fileName,0,$cutTo);
		if($isFileExist){
			return $this->inContext["CONFIG"][$name];
		}else {
			return "Config File does not exist.";
		}
	}
	
	/**
	 * get config of all configfiles
	 * @return mixed array.
	 */
	public function getConfigs(){
		return $this->inContext["CONFIG"];
	}
	
	/**
	 * all changes will be ovewritten in configfile
	 * be care or you will lose all your config
	 * TODO create config temp and store somewhere for backup
	 * @param string $fileName
	 * @param mixed array $newConfig
	 * @return if false or "" or 0 => config couldn't be overwritten else
	 */
	public function saveChangedConfig($newConfig,$fileName){
		return ConfigHelper::writeINI($newConfig,$fileName);
	}
}